package com.student.xujiang.myallstudent.rxjava;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.student.xujiang.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class RxJava1MainActivity extends AppCompatActivity {

    /**
     * 中文文档
     *
     * https://mcxiaoke.gitbooks.io/rxdocs/content/Single.html
     * */
    @BindView(R.id.textView)
    TextView textView;
    @BindView(R.id.bt_create)
    Button btCreate;
    @BindView(R.id.bt_create2)
    Button btCreate2;
    @BindView(R.id.bt_from)
    Button btFrom;
    @BindView(R.id.bt_interval)
    Button btInterval;
    @BindView(R.id.bt_just)
    Button btJust;
    @BindView(R.id.bt_filter)
    Button btFilter;
    @BindView(R.id.bt_range)
    Button btRange;
    @BindView(R.id.activity_rx_java1_main)
    LinearLayout activityRxJava1Main;
    @BindView(R.id.bt_map)
    Button btMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rx_java1_main);
        ButterKnife.bind(this);

        //Rxjava1MainActivity与RxUtils为rxandroid的应用

        //javarx的应用主要是ConcreteWatched那四个
        runjava();
        //Simpler那两个
        runjava2();
    }

    private void runjava2() {
        SimpleObservable simple = new SimpleObservable();
        SimpleObserver observer = new SimpleObserver(simple);

        simple.setData(1);
        simple.setData(2);
        simple.setData(2);
        simple.setData(4);
    }

    private void runjava() {
        Watched xiaoming  = new ConcreteWatched();

        Watcher watcher1 = new ConcreteWatcher();
        Watcher watcher2 = new ConcreteWatcher();
        Watcher watcher3= new ConcreteWatcher();

        xiaoming.addWatcher(watcher1);
        xiaoming.addWatcher(watcher2);
        xiaoming.addWatcher(watcher3);

        xiaoming.notifyWatchers("我走了");
    }

    @OnClick({R.id.bt_create, R.id.bt_create2, R.id.bt_from, R.id.bt_interval, R.id.bt_just, R.id.bt_filter, R.id.bt_range,R.id.bt_map})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_create:
                //调用create方法
                RxUtils.createObserable();
                break;
            case R.id.bt_create2:
                //create的打印  第二种方法
                RxUtils.createPrint();
                break;
            case R.id.bt_from:
                RxUtils.from();
                break;
            case R.id.bt_interval:
                RxUtils.interval();
                break;
            case R.id.bt_just:
                RxUtils.just();
                break;
            case R.id.bt_filter:
                RxUtils.filter();
                break;
            case R.id.bt_range:
                RxUtils.range();
                break;
            case R.id.bt_map:
                RxUtils.map();
                break;
        }
    }
}
